package cn.zhqr.core.service;

import cn.zhqr.core.utils.StockLock;
import cn.zhqr.db.model.WashCardStock;
import org.apache.log4j.Logger;

/**
 * 洗车卡业务
 */
public class CardService {
    public static final CardService instance = new CardService();
    public static final Logger logger = Logger.getLogger(CardService.class);

    public boolean checkStock(Long cardId){
        WashCardStock washCardStock = WashCardStock.dao.findAndLockByCardId(cardId);
        if(washCardStock == null) return false;
        Long stockLock = StockLock.getLockNum(StockLock.Stock.WASH_CARD);
        if(stockLock == null || stockLock < 0){
            stockLock = 0L;
        }
        int stock = washCardStock.getStock() - stockLock.intValue();
        return stock>0;
    }
}
